package com.zbec.mdrs.service;

import com.zbec.framework.security.service.SecurityService;
import com.zbec.mdrs.entity.ColModelConfig;
import com.zbec.mdrs.repository.jpa.ColModelConfigDao;
import com.zbec.mdrs.vo.ColModelConfigVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

/**
 * Created by fxl on 2016/1/20.
 */
@Component
@Transactional
public class ColModelConfigService {

    @Autowired
    private SecurityService securityService;
    @Autowired
    private ColModelConfigDao colModelConfigDao;

    public ColModelConfig saveConfig(ColModelConfigVo vo){
        String loginName= securityService.getCurrentUser().getLoginName();
        ColModelConfig config=null;
        if(vo.getId()!=null && !vo.getId().equals("")){
            config= colModelConfigDao.findOne(vo.getId());
        }
        if(config!=null){
            config.setBusinessTitle(vo.getBusinessTitle());
        }else{
            config=new ColModelConfig();
            config.setLoginName(loginName);
            config.setBusinessType(vo.getBusinessType());
            config.setBusinessTitle(vo.getBusinessTitle());
            colModelConfigDao.save(config);
        }
        return config;
    }

    public ColModelConfig findColModelConfig(String loginName,String businessTtpe){
        return colModelConfigDao.findByLoginNameAndBusinessType(loginName,businessTtpe);
    }
}
